/**
 * @param {string} s
 * @return {number}
 */
var minLength = function(s) {
    const stack = []
    for(let i = 0; i < s.length; i++) {
        if(stack.length !== 0) {
            if(stack[stack.length - 1] == 'C' && s.charAt(i) == 'D') {
                stack.pop()
                continue
            }
            if(stack[stack.length - 1] == 'A' && s.charAt(i) == 'B') {
                stack.pop()
                continue
            }
        }
        stack.push(s.charAt(i))
    }
    return stack.length
};
console.log(minLength("ABFCACDB"));